#include <regx52.h>

extern unsigned int lux;

void uart_isr() interrupt 4
{
	if(RI) 
	{
		RI = 0; lux = SBUF;
		if(lux > 50) lux = 50;
		SBUF = lux;
	}
	if(TI) {TI = 0;}
}

//19200bps@11.0592MHz
void uart_timer1_init(void)	
{
	//PCON &= 0x7F;// 1/32 * (timer1 freq)
	PCON |= 0x80;// 1/16 * (timer1 freq)
	SCON = 0x50; // uart mode 01 enable receive 	
	TMOD = 0x20; //timer1 8bit reload
	TH1 = 0xFD;
	ET1 = 0;     //disable timer1 interrupt
	TR1 = 1;     //timer1 run
	PS = 1; //priority high
	ES = 1; //enable uart interrupt
	EA = 1; //enable all interrupts
}

//9600bps@11.0592MHz
void uart_timer2_init(void) 
{
	SCON = 0x50; // uart mode 01 enable receive
	TCLK = 1;//timer2 as uart Tx clock
	RCLK = 1;//timer2 as uart Rx clock
	RCAP2L = 0xDC;
	RCAP2H = 0xFF;
	ET2 = 0;     //disable timer2 interrupt
	TR2 = 1;     //timer2 run
	PS = 1; //priority high
	ES = 1; //enable uart interrupt
	EA = 1; //enable all interrupts
}
	